<!DOCTYPE composition PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
    xmlns:s="http://jboss.com/products/seam/taglib"
    xmlns:ui="http://java.sun.com/jsf/facelets"
    xmlns:f="http://java.sun.com/jsf/core"
    xmlns:h="http://java.sun.com/jsf/html"
    xmlns:rich="http://richfaces.org/rich"
	xmlns:a="http://richfaces.org/a4j"
    template="/layout/template.xhtml">

<ui:define name="body">

<rich:panel style="padding:0" headerClass="outpanelHeader" styleClass="acab_seat_state_box">
	<f:facet name="header">
		Travel's seat state:
	</f:facet>
	<h:panelGrid columns="1" columnClasses="gridContent">
		<rich:dataList id="seatStateId"
           	    var="_seat"
             	  value="#{travelDialogsBean.travel.seats}"
          	   rendered="#{not empty travelDialogsBean.travel.seats}">
        
      			<h:outputText value="#{_seat.seatNumber}"/>
      			<s:div rendered="#{!_seat.state.equals('FREE')}">
      				<s:graphicImage url="/img/icons/seat_gold.jpg" height="40" />
      				<s:graphicImage value="#{avatarManager.getUsersAvatarByType(_seat.user.idUser, 'MEDIUM')}" rendered="#{avatarManager.getUsersAvatarByType(_seat.user.idUser, 'MEDIUM')!=null}" fileName="#{_seat.user.idUser}"  height="40"/>
				</s:div>
				<s:div rendered="#{_seat.state.equals('FREE')}">
					<s:graphicImage value="/img/icons/seat_black.jpg" height="40" />
          		</s:div>
       	</rich:dataList>

	</h:panelGrid>
</rich:panel>



<rich:panel style="padding:0" headerClass="outpanelHeader" styleClass="acab_top_aligned_box">
	<f:facet name="header">Dialog Search Results (#{empty travelDialogsBean.resultList ? 0 : (travelDialogsBean.paginated ? travelDialogsBean.resultCount : travelDialogsBean.resultList.size)})</f:facet>
	<h:panelGrid columns="2" columnClasses="gridContent">
	
		<rich:panel id="dialogPanelId">
			<f:facet name="header" >Dialogs for travel</f:facet>
			<h:panelGrid>
				<h:outputText value="The dialog search returned no results." rendered="#{empty travelDialogsBean.resultList}"/>
		
	   			<rich:dataTable id="dialogList"
	               	var="_dialog"
	             		value="#{travelDialogsBean.resultList}"
	          			rendered="#{not empty travelDialogsBean.resultList}">
	       			
	       			<h:column>
	           			<f:facet name="header">With user</f:facet>
	           			<h:outputText value="#{_dialog.user.login}"/>
	       				<s:graphicImage value="#{avatarManager.getUsersAvatarByType(_dialog.user, 'SMALL')}" rendered="#{avatarManager.getUsersAvatarByType(_dialog.user.idUser, 'SMALL')!= null}" fileName="#{_dialog.user.idUser}"  height="22"/>
	       			</h:column>
	       			<h:column>
	           			<f:facet name="header">About travel...</f:facet>
	           			<h:form>		
	           				<s:link 
	           					value="#{_dialog.travel.name}"
	           					view="/acab/travel/TravelDetails.xhtml" 
	           					action="#{travelDetailsBean.selectTravelAction}" >
				  				<f:param name="idTravel" value="#{_dialog.travel.idTravel}"/>
							</s:link>
						</h:form>
	       			</h:column>
	       			
	       			
	       			<h:column>
			        
	           			<a:form rendered="#{!travelDialogsBean.userHasSeatInTravel(_dialog.user.idUser)}">
	  						<a:commandLink  reRender="panel"
								oncomplete="Richfaces.showModalPanel('panel', {})">
								<a:actionparam name="userId" value="#{_dialog.user.idUser}" assignTo="#{travelDialogsBean.idUser}" />
								<a:actionparam name="travelName" value="#{_dialog.travel.name}" assignTo="#{travelDialogsBean.travelName}" />
								<a:actionparam name="userName" value="#{_dialog.user.login}" assignTo="#{travelDialogsBean.userName}" />
								<s:graphicImage value="/img/icons/asign_seat.gif" height="22"/>
							</a:commandLink>
			 			</a:form>
			 			
			 			<a:form rendered="#{travelDialogsBean.userHasSeatInTravel(_dialog.user.idUser)}">
	  						<a:commandLink reRender="panel2"
								oncomplete="Richfaces.showModalPanel('panel2', {})">
								<a:actionparam name="userId" value="#{_dialog.user.idUser}" assignTo="#{travelDialogsBean.idUser}" />
								<s:graphicImage value="/img/icons/unasign_seat.gif" height="22"/>
							</a:commandLink>
			 			</a:form>
			           
			        </h:column>
			        
			        
	       			
	       			<h:column>
	       				
			                <h:form> 
			                <a:commandLink id="selectDialog" ajaxSingle="true" actionListener="#{travelDialogsBean.selectDialogActionListener}" reRender="dialogPanelId,conversationPanelId"> 
			                	<s:graphicImage value="#{(_dialog.ownerSeenDate == null || _dialog.ownerSeenDate.before(_dialog.lastCommentDate))? '/img/icons/conv_orange.gif' : '/img/icons/conv_blue.gif'}"  height="22"/> 
			                	<f:param name="selectedDialogId" value="#{_dialog.idDialog}"/>
							</a:commandLink>
							</h:form>
							
	       			</h:column>
	       
	   			</rich:dataTable>
   			</h:panelGrid>
		</rich:panel>
		

		<rich:panel bodyClass="inpanelBody" id="conversationPanelId">
			<f:facet name="header">Conversation:</f:facet>
			
			<h:form id="userSearch" styleClass="edit" >
				<h:inputTextarea cols="100" rows="5" value="#{travelDialogsBean.newMessage}"/>
			
				<div class="actionButtons">
					<a:commandButton value="Send"  actionListener="#{travelDialogsBean.ownerSendMessageActionListener}" reRender="conversationPanelId"/>
        		</div>

    		</h:form>
			
			<h:outputText value="The dialog has no comments?!?!" rendered="#{empty travelDialogsBean.dialogComments}"/>
		
   			<rich:dataTable id="dialogCommentList"
               	var="_comm"
             		value="#{travelDialogsBean.dialogComments}"
          			rendered="#{not empty travelDialogsBean.dialogComments}">
       			
       			<h:column>
           			<h:outputText value="#{_comm.msg}"/>
       			</h:column>
       		</rich:dataTable>
       		
       		
       		
			
		</rich:panel>

		
	</h:panelGrid>
</rich:panel>   	


<!-- The modal panel1 -->   
<rich:modalPanel id="panel" width="350" height="200">
	<f:facet name="header">
		<h:panelGroup>
			<h:outputText value="You are going to asign a seat."></h:outputText>
		</h:panelGroup>
	</f:facet>
	<f:facet name="controls">
		<h:panelGroup>
			<h:graphicImage value="/images/modal/close.png" styleClass="hidelink" id="hidelink"/>
			<rich:componentControl for="panel" attachTo="hidelink" operation="hide" event="onclick"/>
		</h:panelGroup>
	</f:facet>
	

	<h:outputText value="Select a seat of your travel named "/><h:outputText id="modalTravelNameId" value="#{travelDialogsBean.travelName}"/>
	<br/>
	<h:outputText value="to asign to "/><h:outputText id="modalUserNameId" value="#{travelDialogsBean.userName}"/>
	<h:form>
		

		
		
		<rich:dataList id="seatStateId"
           	    var="_seat"
             	  value="#{travelDialogsBean.travel.seats}"
          	   rendered="#{not empty travelDialogsBean.travel.seats}">
        

				<h:commandLink  
					reRender="panel" 
					rendered="#{_seat.state.equals('FREE')}" 
                    action="#{travelDialogsBean.asignSeatToUserAction(_seat.idSeat,travelDialogsBean.idUser)}" >
					

					<s:graphicImage value="/img/icons/seat_black.jpg" height="22" />
					
				</h:commandLink>
				
				
      			<s:graphicImage url="/img/icons/seat_gold.jpg" height="22" rendered="#{!_seat.state.equals('FREE')}"/>

          
       	</rich:dataList>
       	
	</h:form>
 </rich:modalPanel>
 
 
 
 
 <rich:modalPanel id="panel2" width="350" height="200">
	<f:facet name="header">
		<h:panelGroup>
			<h:outputText value="You are going to release a seat!"></h:outputText>
		</h:panelGroup>
	</f:facet>
	<f:facet name="controls">
		<h:panelGroup>
			<h:graphicImage value="/images/modal/close.png" styleClass="hidelink" id="hidelink2"/>
			<rich:componentControl for="panel" attachTo="hidelink2" operation="hide" event="onclick"/>
		</h:panelGroup>
	</f:facet>
	

	<h:outputText value="You are going to release a seat!"/>
	
	<h:form>

		<h:inputHidden  id="toTravel" value="#{findTravelsBean.toTravel}"/>
		<div class="actionButtons">
       		<h:commandButton id="release"
                       value="Release"
                      action="#{travelDialogsBean.releaseByUserAction(travelDialogsBean.idUser)}" />
		</div>
	</h:form>
 </rich:modalPanel>
    

        
        
</ui:define>
</ui:composition>
	